package seqList.LeetCode;

public class Num83 {
    /**LeetCode第83题
     * 删除排序链表的重复元素，重复元素保留1次
     */
        public ListNode deleteDuplicates(ListNode head) {
            ListNode dummyHead = new ListNode(101);
            dummyHead.next = head;
            // prev指向第一个不重复元素
            ListNode prev = dummyHead;
            ListNode cur = prev.next;
            while (cur != null) {
                if (prev.val == cur.val) {
                    // 此时cur需要删除
                    prev.next = cur.next;
                }else {
                    // prev和cur不是重复元素，都向后移动一个单位
                    prev = prev.next;
                }
                cur = cur.next;
            }
            return dummyHead.next;
        }
    }

